package com.application.chiettinhdienluc.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.application.chiettinhdienluc.R;
import com.application.chiettinhdienluc.control.GridFunctionItem;

public class GridMoresAdapter extends BaseAdapter {

	private ArrayList<GridFunctionItem> itemList;
	public LayoutInflater inflater = null;
	public Activity context;

	public void setItemList(ArrayList<GridFunctionItem> itemList) {		
		this.itemList = new ArrayList<GridFunctionItem>(itemList);
	}

	public GridMoresAdapter(Activity context, ArrayList<GridFunctionItem> listFunc) {
		super();
		this.context = context;
		this.itemList = listFunc;
		this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public static class ViewHolder{
		public LinearLayout funcLayoutitem;
		public ImageView 	funcIconitem;
		public TextView  	funcNameitem;
	}

	public void changeDataList(ArrayList<GridFunctionItem> data) {
		itemList = data;
	}

	@Override
	public int getCount() {
		if (itemList == null) return 0;
		return itemList.size();
	}

	@Override
	public Object getItem(int n) {
		if (itemList==null || itemList.size()<=n || n<0) return null;
		return itemList.get(n);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;

		if(convertView == null)
		{
			holder = new ViewHolder();

			convertView = inflater.inflate(R.layout.moresgrid_details_row, null);

			holder.funcIconitem =   (ImageView) convertView.findViewById(R.id.funcIconitem);
			holder.funcNameitem =   (TextView) convertView.findViewById(R.id.funcNameitem);

			convertView.setTag(holder);			
		}
		else
		{
			holder = (ViewHolder)convertView.getTag();			
		}

		try {

			final GridFunctionItem funcInfo = (GridFunctionItem)itemList.get(position);

			holder.funcNameitem.setText(funcInfo.getFunctionName());
//			holder.funcIconitem.setImageResource(funcInfo.getGridFuncIconResId());
			
//			if(!funcInfo.getGridFuncIconUrl().equals(""))
//				//GlobalData.imageLoader.displayImage(GlobalData.userInfo.avt, holder.funcIconitem, GlobalData.options_avatar);
//				GlobalData.aq.id(holder.funcIconitem).image(GlobalData.userInfo.avt, GlobalData.opt_gallery);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return convertView;
	}

}
